/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aliasMatching.model;

import aliasMatching.controller.TimeEquality;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Alias {

    private List<Float> featureVector;
   // private List timeVector;
    private int nrOfFeatures;
    private String user;
   // private String userID;
    private ArrayList<ArrayList<Float>> featureVectorPostList;
    public List<String> posts;
    public List<String> postTime;
    private double[] timeStamp;

    public Alias(String userID) throws SQLException {
        this.user = userID;
        //setNrOfFeatures(293 + 20 + 26 + 21 + 6);
       //setNrOfFeatures(26 + 21 + 293 + 20);
       setNrOfFeatures(26 + 21 + 293 + 20 + 1);
        //setNrOfFeatures(293);
        featureVector = new ArrayList<Float>();
        featureVectorPostList = new ArrayList<ArrayList<Float>>();
       // timeVector = new ArrayList();
    }

    @Override
    public String toString(){
        return user;
    }

    /**
     * Returns all posts of user
     */
    public static List<String> getAllPosts(int ID) throws SQLException {
        List<String> messages = new ArrayList<String>();
        messages = TimeEquality.getAllPost(ID);
        return messages;
    }

    public ArrayList<ArrayList<Float>> initializeFeatureVectorPostList() {
        ArrayList<ArrayList<Float>> list = new ArrayList<ArrayList<Float>>();
        for (int j = 0; j < posts.size(); j++) {
            ArrayList<Float> featList = new ArrayList<Float>();
            for (int i = 0; i < nrOfFeatures; i++) {
                featList.add(0.0f);
            }
            list.add(featList);
        }
        return list;
    }

    public String getUserID() {
        return user;
    }

    public void setUserID(String userID) {
        this.user = userID;
    }
    
   
    public List<String> getPosts() {
        return posts;
    }

    public void setPosts(List<String> posts) {
        this.posts = posts;
    }

    public void addPost(String post) {
        posts.add(post);
    }

    public void addToFeatureVectorPostList(ArrayList<Float> freqDist, int startIndex, int index) {
        for (int i = 0; i < freqDist.size(); i++) {
            featureVectorPostList.get(index).set(startIndex, freqDist.get(i));
            startIndex++;
        }
    }

    public List<Float> getFeatureVector() {
        return featureVector;
    }

    public void setFeatureVector(List<Float> featureVector) {
        this.featureVector = featureVector;
    }

    public ArrayList<ArrayList<Float>> getFeatureVectorPosList() {
        return featureVectorPostList;
    }

    public void setFeatureVectorPosList(ArrayList<ArrayList<Float>> list) {
        featureVectorPostList = list;
    }

    public void setFeatureValue(int index, float newValue) {
        featureVector.set(index, newValue);
    }

    public int getNrOfFeatures() {
        return nrOfFeatures;
    }

    public void setNrOfFeatures(int nrOfFeatures) {
        this.nrOfFeatures = nrOfFeatures;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public double[] getTimeVector() throws SQLException {

        double[] rr = new double[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

        Iterator itr = postTime.iterator();

        while (itr.hasNext()) {
            Timestamp key = (Timestamp) itr.next();
            int hr = key.getHours();
            rr[hr]++;
        }
        return rr;
    }

    public static double[] getTimeVectorArray(List postTime) throws SQLException {

        double[] rr = new double[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        Iterator itr = postTime.iterator();

        while (itr.hasNext()) {
            Timestamp key = (Timestamp) itr.next();
            int hr = key.getHours();
            rr[hr]++;
        }
        return rr;
    }

    public void setTimeStamp(double[] rr) {
        this.timeStamp = rr;
    }

    public double[] getTimeStamp() {
        return timeStamp;
    }

    /**
     * return posts of respective user
     * @param tempUser
     * @return
     * @throws SQLException
     */
    public static List getAllPostTime(int tempUser) throws SQLException {
        List tempTime = new ArrayList();
        tempTime = TimeEquality.getPostTime(tempUser);
        return tempTime;
    }

    public void setPostTime(List postTime) {
        this.postTime = postTime;
    }

    public List getPostTime() {
        return postTime;
    }
}
